﻿<DemoScriptLoader @ref=@highlightLoaderRef
                  Src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.2.0/build/highlight.min.js" />
<DemoScriptLoader @ref=@cshtml Src="_content/BlazorDemo/lib/cshtml-razor.js" />
<DemoScriptLoader @ref=@initCshtmlLoaderRef
                  Code="function initcshtml() {
    hljs.registerLanguage('cshtml-razor', window.hljsDefineCshtmlRazor);
    hljs.initHighlightingOnLoad();
}" />
<pre><code @ref=@codeBlockRef class="hljs @Language">@ChildContent</code></pre>
@code {

    [Parameter] public RenderFragment ChildContent { get; set; }
    [Parameter] public string Language { get; set; } = "cshtml-razor";

    ElementReference codeBlockRef;
    DemoScriptLoader highlightLoaderRef;
    DemoScriptLoader cshtml;
    DemoScriptLoader initCshtmlLoaderRef;
    protected override async Task OnAfterRenderAsync(bool firstRender) {
        if(firstRender) {
            try {
                await Task.WhenAll(highlightLoaderRef.Loaded, cshtml.Loaded);
                await initCshtmlLoaderRef.InvokeVoidAsync("initcshtml");
                await highlightLoaderRef.InvokeVoidAsync("hljs.highlightBlock", codeBlockRef);
            } catch { }
        }
        await base.OnAfterRenderAsync(firstRender);
    }
}
